
 ; Program to find out the binary equivalent of a given number
 ; which is max 2 digits long
 ;          e.g :- To enter 1, enter 01 as the input

 data segment
   copy db 10,13,'               ',
        db 'CONVERSION OF INTEGER TO ITS BINARY EQUIVALENT',10,13,'$'
   mes1 db 10,13,10,13,'Enter A Number (max. 2 digits) : $'
   mes2 db 10,13,10,13,'Binary Equivalent              : $'
   str db 5,?,3 dup (0)
   integer db 0
 data ends

 code segment
   assume cs : code , ds : data

   begin  : mov ax,data     ; initialize the
            mov ds,ax       ; data segment

            mov ah,9        ; print the title
            lea dx,copy     ; of the program and
            int 21h         ; the copyright message

            mov ah,9        ; display
            lea dx,mes1     ; the first
            int 21h         ; message

            mov ah,0ah      ; read the
            lea dx,str      ; number to
            int 21h         ; be converted

            mov bx,2        ; convert
            mov al,str[bx]  ; the
            sub al,'0'      ; input
            mov ah,0        ; number
            mov bl,10       ; from
            mul bl          ; string
            mov integer,al  ; to
            mov bx,3        ; its
            mov al,str[bx]  ; equivalent
            sub al,'0'      ; integer
            add integer,al  ; value

            mov ah,9        ; display
            lea dx,mes2     ; the second
            int 21h         ; message

            mov cx,8        ; setup cx as counter
   repeat : rcl integer,1   ; rotate by one thru' carry
                            ; is the carry flag 1 ?
            jc one          ; yes, jump to one
            mov ah,2        ; no, print
            mov dl,'0'      ; a
            int 21h         ; '0'
            jmp next        ; go for next bit
   one    : mov ah,2        ; print
            mov dl,'1'      ; a
            int 21h         ; '1'
   next   : loop repeat     ; repeat till all bits over

            mov ah,4ch      ; terminate
            int 21h         ; the program
 code ends
   end begin
